package com.ihr360.message.modal;

import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class WxMpProgramTemplateMessage implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8774354964110893058L;
	private String toUser;
	private String templateId;
	private String page;
	private String index;
	private String topColor;
	private String formId;
	private String emphasisKeyword;
	private List<WxMpTemplateData> datas = new ArrayList<WxMpTemplateData>();
	public String getToUser() {
		return toUser;
	}
	public void setToUser(String toUser) {
		this.toUser = toUser;
	}
	
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public String getTemplateId() {
		return templateId;
	}
	public void setTemplateId(String templateId) {
		this.templateId = templateId;
	}
	public String getIndex() {
		return index;
	}
	public void setIndex(String index) {
		this.index = index;
	}
	public String getTopColor() {
		return topColor;
	}
	public void setTopColor(String topColor) {
		this.topColor = topColor;
	}
	public String getFormId() {
		return formId;
	}
	public void setFormId(String formId) {
		this.formId = formId;
	}
	public String getEmphasisKeyword() {
		return emphasisKeyword;
	}
	public void setEmphasisKeyword(String emphasisKeyword) {
		this.emphasisKeyword = emphasisKeyword;
	}
	public List<WxMpTemplateData> getDatas() {
		return datas;
	}
	public void setDatas(List<WxMpTemplateData> datas) {
		this.datas = datas;
	}
	
	public String toJson() {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("touser", this.getToUser());
		jsonObject.put("template_id", this.getTemplateId());
		jsonObject.put("page", this.getPage());
		jsonObject.put("form_id", this.getFormId());
		jsonObject.put("emphasis_keyword", this.getEmphasisKeyword());
		JSONObject dataJsonObject = new JSONObject();
		this.datas.forEach(data -> {
			JSONObject dataItem = new JSONObject();
			dataItem.put("value", data.getValue());
			dataJsonObject.put(data.getName(), dataItem);
		});
		jsonObject.put("data", dataJsonObject);
		return jsonObject.toJSONString();
	}
}
